package com.cdtu.store.test;

import com.cdtu.store.common.entity.CategoryEntity;
import com.cdtu.store.common.entity.SpecGroupEntity;
import com.cdtu.store.common.entity.SpecParamEntity;
import com.cdtu.store.item.StoreApplication8080;
import com.cdtu.store.item.service.CategoryService;
import com.cdtu.store.item.service.SpecGroupService;
import com.cdtu.store.item.service.SpecParamService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

/**
 * @author dongyuhao
 */
@SpringBootTest(classes = StoreApplication8080.class)
@RunWith(SpringRunner.class)
public class SyncSpecParam {
    @Autowired
    private SpecParamService specParamService;
    @Autowired
    private CategoryService categoryService;
    @Autowired
    private SpecGroupService specGroupService;
    @Test
    public void sync(){
        List<SpecParamEntity> specParams = specParamService.list();
        specParams.forEach(param->{
            CategoryEntity categoryEntity = this.categoryService.getById(param.getCid());
            param.setCategoryName(categoryEntity.getName());
            SpecGroupEntity specGroupEntity = this.specGroupService.getById(param.getGroupId());
            param.setGroupName(specGroupEntity.getName());
            this.specParamService.updateById(param);
        });
    }
}
